# -*- coding: utf-8 -*-


class CoreException(Exception):
    msg_fmt = 'An internal server error occurred.'
    code = 'InternalError'

    def __init__(self, message=None, **kwargs):
        super_code = self.__class__.__bases__[0].__name__
        code = self.__class__.__name__
        code = code.replace(super_code, super_code + '.', 1)

        if self.code == CoreException.code:
            self.code = code

        self.kwargs = kwargs

        if not message:
            try:
                message = self.msg_fmt % kwargs
            except Exception:
                message = self.msg_fmt

        # self.ori_message = message
        # message = '%(code)s: %(message)s' % {'code': self.code, 'message': message}
        self.message = message
        super(CoreException, self).__init__(message)


class GetBusinessLockError(CoreException):
    msg_fmt = 'Get business lock failed.'
    code = 'InternalError.GetBusinessLockError'
